
package vip.xiaonuo.biz.modular.lancerCoupon.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.biz.modular.lancerCoupon.entity.BizCoupon;
import vip.xiaonuo.biz.modular.lancerCoupon.param.BizCouponAddParam;
import vip.xiaonuo.biz.modular.lancerCoupon.param.BizCouponEditParam;
import vip.xiaonuo.biz.modular.lancerCoupon.param.BizCouponIdParam;
import vip.xiaonuo.biz.modular.lancerCoupon.param.BizCouponPageParam;
import vip.xiaonuo.biz.modular.lancerCoupon.service.BizCouponService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

/**
 * 优惠券表控制器
 *
 * @author Lancer
 * @date  2024/03/03 16:29
 */
@Api(tags = "优惠券(B端)")
@ApiSupport(author = "LANCER_TEAM", order = 1)
@RestController
@Validated
public class BusCouponController {

    @Resource
    private BizCouponService bizCouponService;

    /**
     * 获取优惠券表分页
     *
     * @author Lancer
     * @date  2024/03/03 16:29
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation("B端获取优惠券表分页")
    @SaCheckPermission("/biz/business/coupon/page")
    @GetMapping("/biz/business/coupon/page")
    public CommonResult<Page<BizCoupon>> page(BizCouponPageParam bizCouponPageParam) {
        return CommonResult.data(bizCouponService.pageBus(bizCouponPageParam));
    }

    /**
     * 添加优惠券表
     *
     * @author Lancer
     * @date  2024/03/03 16:29
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("B端添加优惠券表")
    @CommonLog("添加优惠券表")
    @SaCheckPermission("/biz/business/coupon/add")
    @PostMapping("/biz/business/coupon/add")
    public CommonResult<String> add(@RequestBody @Valid BizCouponAddParam bizCouponAddParam) {
        bizCouponService.add(bizCouponAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑优惠券表
     *
     * @author Lancer
     * @date  2024/03/03 16:29
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation("B端编辑优惠券表")
    @CommonLog("编辑优惠券表")
    @SaCheckPermission("/biz/business/coupon/edit")
    @PostMapping("/biz/business/coupon/edit")
    public CommonResult<String> edit(@RequestBody @Valid BizCouponEditParam bizCouponEditParam) {
        bizCouponService.editBus(bizCouponEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除优惠券表
     *
     * @author Lancer
     * @date  2024/03/03 16:29
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("B端删除优惠券表")
    @CommonLog("删除优惠券表")
    @SaCheckPermission("/biz/business/coupon/delete")
    @PostMapping("/biz/business/coupon/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   CommonValidList<BizCouponIdParam> bizCouponIdParamList) {
        bizCouponService.delete(bizCouponIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取优惠券表详情
     *
     * @author Lancer
     * @date  2024/03/03 16:29
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation("B端获取优惠券表详情")
    @SaCheckPermission("/biz/business/coupon/detail")
    @GetMapping("/biz/business/coupon/detail")
    public CommonResult<BizCoupon> detail(@Valid BizCouponIdParam bizCouponIdParam) {
        return CommonResult.data(bizCouponService.detail(bizCouponIdParam));
    }
}
